package request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 *
 * 请求头数据的获取1
 *
 * @author Mc.Chai
 * @program: JavaWeb
 * @create 2022-03-20-17:16 17:16
 */
    @WebServlet("/myRequest3")
    public class MyRequest3 extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求头数据：User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
        String header = request.getHeader("user-agent");
        //判断请求的数据中是否存在一下关键字
        if (header.contains("Chrome")){
            System.out.println("谷歌");
        }else if (header.contains("Safari")){
            System.out.println("Safari");
        }
    }
}
